<?php

namespace App\Model\Api;

use App\Model\BaseModel;
use App\Model\Number;
use Illuminate\Support\Facades\DB;

class FamilyRoom extends BaseModel
{
    protected $connection = 'api';
    protected $table = 'family_room';
    protected $primaryKey = 'room_id';

    public function getAllFamilyRoom($room_id) {
        $where['room.room_id'] = $room_id;
        $res = DB::connection($this->connection)->table($this->table)
            ->leftjoin('room', 'family_room.room_id', 'room.room_id')
            ->leftjoin('family', 'family.family_id', 'family_room.family_id')
            ->where($where)
            ->select('family_uid','family_name')
            ->first();
        return $this->objToArray($res);
    }

    public function number() {
        return $this->belongsTo(Number::class,'user_id','user_id');
    }
}
